package mat;


public abstract class MatRowWorker implements Runnable, Cloneable
{
	protected String name;
	
	protected double[][] result;
	protected double[][] A;
	protected double[][] B;
	protected double value;

	protected int index = -1;
	protected int iStart;
	protected int iEnd;
	
	public static int rows(double[][] a)
	{
		return a == null ? 0 : a.length;
	}
	
	public static int cols(double[][] a)
	{
		return a == null || a.length == 0 ? 0 : a[0].length;
	}

	public MatRowWorker(double[][] A)
	{
		this.A = A;
	}
	
	public MatRowWorker(String name, double[][] result, double[][] A, double[][] B)
	{
		this.name = name;
		this.result = result;
		this.A = A;
		this.B = B;
	}
	
	public MatRowWorker(String name, double[][] result, double[][] A, double value)
	{
		this.name = name;
		this.result = result;
		this.A = A;
		this.value = value;
	}

	
	public MatRowWorker shallowCopy()
	{
		MatRowWorker clone = null;
		try
		{
			clone = (MatRowWorker) this.clone();
		}
		catch (CloneNotSupportedException e)
		{
			// should NEVER happen
			e.printStackTrace();
		}
		return clone;
	}
	
	public void setBounds(int iStart, int iEnd)
	{
		this.iStart = iStart;
		this.iEnd = iEnd;
	}
	
	public void setIndex(int index)
	{
		this.index = index;
	}
	
	public int numberOfCalculations()
	{
		if (B == null)
			return rows(A) * cols(A);
		else
			return Math.max(rows(A), cols(A)) * Math.max(rows(B), cols(B));			
	}
	
	public int calculationsPerThread()
	{
		return 1000;
	}
		
	public int proposeNumberOfThreads()
	{
		return numberOfCalculations() / calculationsPerThread();
	}
	
	public double[][] getA()
	{
		return A;
	}
	
	public double[][] getResult()
	{
		return result;
	}
	
	public String getName()
	{
		return name;
	}
}


